package com.chanyachting.emall.serviceImpl;

import java.util.List;

import com.chanyachting.emall.dao.MemberaccountDAO;
import com.chanyachting.emall.domain.Member;
import com.chanyachting.emall.domain.Memberaccount;
import com.chanyachting.emall.service.MemberaccountService;

public class MemberaccountServiceImpl implements MemberaccountService {
	
	private MemberaccountDAO maDao;

	public MemberaccountServiceImpl() {
		
		this.maDao=new MemberaccountDAO();
	}

	public boolean closeMemberaccount(Memberaccount maccount) {
		
		maccount.setStatus("00");
		
		this.maDao.update(maccount);
		
		return true;
	}

	public boolean createMemberaccount(Memberaccount maccount) {
		
		this.maDao.save(maccount);
		
		return true;
	}

	public List<Memberaccount> getAllMemberaccount() {
		
		return this.maDao.find("from Memberaccount");
	}

	public Memberaccount getMemberaccountByMember(Member member) {
		
		String args []={String.valueOf(member.getId())};
		
		List list= this.maDao.find("from Memberaccount where memberId=?", args);
		
		if(list!=null && list.size()>0) return (Memberaccount)list.get(0);
		
		return null;
	}

	public Memberaccount getOneMemberaccount(Memberaccount maccount) {
		
		return (Memberaccount) this.maDao.load(Memberaccount.class, maccount.getId());
	}

	public boolean openMemberaccount(Memberaccount maccount) {
		
		maccount.setStatus("01");
		
		this.maDao.update(maccount);
		
		return true;
		
	}

	public boolean updateMemberaccount(Memberaccount maccount) {
		
		this.maDao.update(maccount);
		
		return true;
		
	}

}
